/*    */ package org.appfuse.util;
/*    */ 
/*    */ import java.text.DateFormat;
/*    */ import java.text.SimpleDateFormat;
/*    */ import java.util.Date;
/*    */ import org.apache.commons.beanutils.ConversionException;
/*    */ import org.apache.commons.lang.StringUtils;
/*    */ 
/*    */ public class TimestampConverter extends DateConverter
/*    */ {
/* 21 */   public static final String TS_FORMAT = DateUtil.getDatePattern() + " HH:mm:ss.S";
/*    */ 
/*    */   protected Object convertToDate(Class type, Object value)
/*    */   {
/* 30 */     DateFormat df = new SimpleDateFormat(TS_FORMAT);
/* 31 */     if ((value instanceof String)) {
/*    */       try {
/* 33 */         if (StringUtils.isEmpty(value.toString())) {
/* 34 */           return null;
/*    */         }
/*    */ 
/* 37 */         return df.parse((String)value);
/*    */       } catch (Exception pe) {
/* 39 */         throw new ConversionException("Error converting String to Timestamp");
/*    */       }
/*    */     }
/*    */ 
/* 43 */     throw new ConversionException("Could not convert " + value.getClass().getName() + " to " + type.getName());
/*    */   }
/*    */ 
/*    */   protected Object convertToString(Class type, Object value)
/*    */   {
/* 54 */     DateFormat df = new SimpleDateFormat(TS_FORMAT);
/* 55 */     if ((value instanceof Date)) {
/*    */       try {
/* 57 */         return df.format(value);
/*    */       } catch (Exception e) {
/* 59 */         throw new ConversionException("Error converting Timestamp to String");
/*    */       }
/*    */     }
/*    */ 
/* 63 */     return value.toString();
/*    */   }
/*    */ }

